<?php
/**
 * User: Feng
 * Date: 2024/08/05
 */

namespace app\Manage\controller;

use app\common\controller\Manage;

class Apply extends Manage
{
	public function lists()
	{
		if ($this->request->isAjax()) {
			return (new \app\common\model\Apply())->tableData(input('param.'));
		}
		return $this->fetch('lists');
	}

	public function status()
	{
		if ($this->request->isPost()) {
			$data = [
				'id'      => input('post.id'),
				'type_id' => input('post.type_id'),
				'title'   => input('post.title'),
				'brief'   => input('post.brief'),
				'pic'     => input('post.pic'),
				'source'  => input('post.source'),
				'content' => input('post.content'),
			];
			return (new \app\common\model\Resource())->saveData($data);
		}
		$info = (new \app\common\model\Resource())->get(input('param.id/d'));
		if (! $info) {
			return error_code(10002);
		}
		$type = (new \app\common\model\ResourceType())->field('id, name')->all();
		return $this->fetch('edit', [
			'info' => $info,
			'type' => $type
		]);
	}

	public function del()
	{
		$result = [
			'status' => true,
			'msg'    => '删除成功',
			'data'   => ''
		];
		if (! (new \app\common\model\Resource())->where(['id' => input('param.id/d')])->delete()) {
			return error_code(10023);
		}
		return $result;
	}
}